<template>
  <centre>
    <h1>登录验证中...</h1>
  </centre>
</template>

<script>
import Centre from "@/components/Centre";
import {mapState} from 'vuex'

export default {
  name: "Auth",
  components: {Centre},
  methods: {
    handleLogin() {
      if (this.isLoading) {
        return;
      }
      if (this.data !== null) {
        let to = this.$route.query.redirect;
        if (to){
          this.$router.push(to)
        }else {
          this.$router.push({name: 'personal'})
        }
      } else {
        this.$router.push({name: 'login'})
      }
    }
  },
  computed: mapState('loginUser', ['data', 'isLoading']),
  watch: {
    data: {
      immediate: true,
      handler() {
        this.handleLogin()
      }
    },
    isLoading: {
      immediate: true,
      handler() {
        this.handleLogin()
      }
    }
  }
}
</script>

<style scoped>
h1 {
  color: #303133;
  font-size: 1.5rem;
}
</style>